<?php 
  error_reporting(E_ALL^E_NOTICE); //取消警告显示
  header('Content-type:application/json');
  date_default_timezone_set("Asia/Shanghai");
  include $_SERVER['DOCUMENT_ROOT']."/common/fun.php";
  include "../conn.php";//https

  $userid = get_post_para('userid',true);
  $deviceid = get_post_para('deviceid',true);
  $moduleid = get_post_para('moduleid',true);
  $type = get_post_para('type',true);

  //说明：device_$type,模块表是device_type的形式,因此根据type自动定位到对应的表
  $sql_delete = "DELETE FROM device_$type where userid='$userid' and deviceid = '$deviceid' and moduleid = '$moduleid'";
  $res_delete = mysqli_query($con,$sql_delete);
  if ($res_delete){
    //将大于该模块ID的模块全部减一
    $sql_update = "update device_$type set moduleid = moduleid-1 where userid='$userid' and deviceid = '$deviceid' and moduleid > $moduleid";
    mysqli_query($con,$sql_update);
  	$myArray["resault"] = 'success';
  } 
  else{
  	$myArray["msg"]=mysqli_error($con);
  	$myArray["resault"] = 'fail';
  }
  $json = json_encode($myArray,JSON_UNESCAPED_UNICODE);
  echo $json;
?>
